import { IPSEditor } from './ipseditor';
import { IPSEditorItem } from './ipseditor-item';
import { IPSNavigateContext } from './ipsnavigate-context';
import { IPSNavigateParam } from './ipsnavigate-param';
import { IPSNavigateParamContainer } from './ipsnavigate-param-container';
import { IPSSysCss } from '../res/ipssys-css';
import { IPSSysDictCat } from '../res/ipssys-dict-cat';
import { IPSSysPFPlugin } from '../res/ipssys-pfplugin';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSEditorImpl extends PSModelObjectImpl implements IPSEditor, IPSNavigateParamContainer {
  get codeName(): string {
    return this.M.codeName;
  }

  get cssStyle(): string {
    return this.M.cssStyle;
  }

  get dynaClass(): string {
    return this.M.dynaClass;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get editorHeight(): number {
    return this.M.editorHeight != null ? this.M.editorHeight : 0.0;
  }

  get editorParams(): IModel {
    return this.M.editorParams;
  }

  get editorStyle(): string {
    return this.M.editorStyle;
  }

  get editorType(): string {
    return this.M.editorType;
  }

  get editorWidth(): number {
    return this.M.editorWidth != null ? this.M.editorWidth : 0.0;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get objectIdField(): string {
    return this.M.objectIdField;
  }

  get objectNameField(): string {
    return this.M.objectNameField;
  }

  get objectValueField(): string {
    return this.M.objectValueField;
  }

  protected pseditoritems: IPSEditorItem[] | null = null;

  getPSEditorItems(): IPSEditorItem[] | null {
    if (this.pseditoritems == null) {
      this.pseditoritems = this.fillChildListModel(this.M.getPSEditorItems, 'control.IPSEditorItem') as IPSEditorItem[];
    }
    return this.pseditoritems;
  }

  get psEditorItems(): IPSEditorItem[] | null {
    return this.getPSEditorItems();
  }

  findPSEditorItem(objKey: any): IPSEditorItem | null {
    return this.getPSModel5('control.IPSEditorItem', this.getPSEditorItems(), objKey) as IPSEditorItem;
  }

  protected psnavigatecontexts: IPSNavigateContext[] | null = null;

  getPSNavigateContexts(): IPSNavigateContext[] | null {
    if (this.psnavigatecontexts == null) {
      this.psnavigatecontexts = this.fillChildListModel(this.M.getPSNavigateContexts, 'control.IPSNavigateContext') as IPSNavigateContext[];
    }
    return this.psnavigatecontexts;
  }

  get psNavigateContexts(): IPSNavigateContext[] | null {
    return this.getPSNavigateContexts();
  }

  findPSNavigateContext(objKey: any): IPSNavigateContext | null {
    return this.getPSModel5('control.IPSNavigateContext', this.getPSNavigateContexts(), objKey) as IPSNavigateContext;
  }

  protected psnavigateparams: IPSNavigateParam[] | null = null;

  getPSNavigateParams(): IPSNavigateParam[] | null {
    if (this.psnavigateparams == null) {
      this.psnavigateparams = this.fillChildListModel(this.M.getPSNavigateParams, 'control.IPSNavigateParam') as IPSNavigateParam[];
    }
    return this.psnavigateparams;
  }

  get psNavigateParams(): IPSNavigateParam[] | null {
    return this.getPSNavigateParams();
  }

  findPSNavigateParam(objKey: any): IPSNavigateParam | null {
    return this.getPSModel5('control.IPSNavigateParam', this.getPSNavigateParams(), objKey) as IPSNavigateParam;
  }

  protected pssyscss: IPSSysCss | null = null;

  getPSSysCss(): IPSSysCss | null {
    if (this.pssyscss != null) return this.pssyscss;
    const value = this.M.getPSSysCss;
    if (value == null) {
      return null;
    }
    this.pssyscss = this.getPSModel4('res.IPSSysCss', value, 'getPSSysCss') as IPSSysCss;
    return this.pssyscss;
  }

  get psSysCss(): IPSSysCss | null {
    return this.getPSSysCss();
  }

  getPSSysCssMust(): IPSSysCss {
    const value = this.getPSSysCss();
    if (value == null) {
      throw new Error('未指定界面样式表');
    }
    return value;
  }

  protected pssysdictcat: IPSSysDictCat | null = null;

  getPSSysDictCat(): IPSSysDictCat | null {
    if (this.pssysdictcat != null) return this.pssysdictcat;
    const value = this.M.getPSSysDictCat;
    if (value == null) {
      return null;
    }
    this.pssysdictcat = this.getPSModel4('res.IPSSysDictCat', value, 'getPSSysDictCat') as IPSSysDictCat;
    return this.pssysdictcat;
  }

  get psSysDictCat(): IPSSysDictCat | null {
    return this.getPSSysDictCat();
  }

  getPSSysDictCatMust(): IPSSysDictCat {
    const value = this.getPSSysDictCat();
    if (value == null) {
      throw new Error('未指定辅助输入词条分类');
    }
    return value;
  }

  protected pssyspfplugin: IPSSysPFPlugin | null = null;

  getPSSysPFPlugin(): IPSSysPFPlugin | null {
    if (this.pssyspfplugin != null) return this.pssyspfplugin;
    const value = this.M.getPSSysPFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyspfplugin = this.getPSModel4('res.IPSSysPFPlugin', value, 'getPSSysPFPlugin') as IPSSysPFPlugin;
    return this.pssyspfplugin;
  }

  get psSysPFPlugin(): IPSSysPFPlugin | null {
    return this.getPSSysPFPlugin();
  }

  getPSSysPFPluginMust(): IPSSysPFPlugin {
    const value = this.getPSSysPFPlugin();
    if (value == null) {
      throw new Error('未指定前端扩展插件');
    }
    return value;
  }

  get placeHolder(): string {
    return this.M.placeHolder;
  }

  get predefinedType(): string {
    return this.M.predefinedType;
  }

  get textSeparator(): string {
    return this.M.textSeparator;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get valueSeparator(): string {
    return this.M.valueSeparator;
  }

  get valueType(): 'SIMPLE' | 'SIMPLES' | 'OBJECT' | 'OBJECTS' | 'USER' | 'USER2' {
    return this.M.valueType || 'SIMPLE';
  }

  get disabled(): boolean {
    return this.M.disabled != null ? this.M.disabled : false;
  }

  get editable(): boolean {
    return this.M.editable != null ? this.M.editable : true;
  }

  get readOnly(): boolean {
    return this.M.readOnly != null ? this.M.readOnly : false;
  }

  get cls(): string {
    return 'PSEditorImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSEditor' || cls == 'control.IPSNavigateParamContainer') return true;
    return super.instanceof(cls);
  }
}
